home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / CommentConverter 1.0.0 / Think C 7.0 Project / Sources / Apple.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-15  |  22.4 KB  |  833 lines  |  [TEXT/KAHL]

  1. #ifndef bscoc
  2. #define bscoc
  3. #ifdef apple
  4. // Alternativ: #pragma once
  5.  
  6.  
  7. /***************************************************************************/
  8. /*****   Datei, die Event-MCP und Multitasking/QuitApp Funktionen      *****/
  9. /*****   für SETI bereitstellt.                                        *****/
  10. /*****   Autor:    Andreas Amoroso                                     *****/
  11. /*****   Datum:    11.8.1993                                           *****/
  12. /***************************************************************************/
  13.  
  14.  
  15.  
  16. // Module with Functions for the MCP-Environment. Requires availability of System-7
  17. //=================================================================================
  18.  
  19.  
  20. // Most of these Headers may be included by Think-C, but those are needed
  21.  
  22. #include <ctype.h>
  23. #include <fcntl.h>
  24. #include <float.h>
  25. #include <limits.h>
  26. #include <math.h>
  27. #include <size_t.h>
  28. #include <stat.h>
  29. #include <stdarg.h>
  30. #include <time.h>
  31.  
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #include <stdio.h>
  35. #include <GestaltEqu.h>
  36. #include <Files.h>
  37. #include <TextEdit.h>
  38. #include <Dialogs.h>
  39. #include <types.h>
  40. #include <pascal.h>
  41. #include <Events.h>
  42. #include <EPPC.h>
  43. #include <AppleEvents.h>
  44. #include <OSEvents.h>
  45.  
  46.  
  47. #include "Apple.h"
  48. #include "Help.h"
  49.  
  50. #ifdef modus_mcp
  51.  
  52. extern char console_environment;    // Definiert in Console.c, Einzige Änderung in Console.c: diese Var global statt static!!!
  53.                     // Daher Custom ANSI 6.0.0 Console…
  54. int    argc=0;
  55. static     Boolean gDone = FALSE;
  56. static Str255    argv[maxFiles];
  57.  
  58. static unsigned short Modis = 0;
  59.  
  60.  
  61.  
  62. /*void    InitToolbox(void)        // Standard initialization calls
  63. *{
  64. *    InitGraf(&thePort);
  65. *    InitFonts();
  66. *    InitWindows();
  67. *    InitMenus();
  68. *    TEInit();
  69. *    InitDialogs(nil);
  70. *    InitCursor();
  71. *    MaxApplZone();            // Aus Handbuch
  72. *    FlushEvents (everyEvent,0);
  73. *}
  74. *    Ersetzt durch ANSI InitConsole()!!!
  75. */
  76.  
  77.  
  78. static void InitTBandCON(void)
  79. {
  80.  
  81.     MenuHandle menu,appleMenu;
  82. // static MenuHandle appleMenu;    in Console.c
  83.     int i;
  84.  
  85.         /*  initialize the Memory Manager  */
  86.     
  87.     if (ROM85 >= 0)
  88.         MaxApplZone();
  89.     for (i = 0; i < 10; i++)
  90.         MoreMasters();
  91.     
  92.         /*  initialize Quickdraw  */
  93.     
  94.     InitGraf(NewPtr(206) + 202);
  95.     
  96.         /*  initialize the Toolbox  */
  97.         
  98.     InitFonts();
  99.     InitWindows();
  100.     TEInit();
  101.     InitDialogs(0);
  102.     InitMenus();
  103.     
  104.         /*  create menus  */
  105.         
  106.     InsertMenu(appleMenu = NewMenu(1, "\p\024"), 0);
  107.     AddResMenu(appleMenu, 'DRVR');
  108.     InsertMenu(menu = NewMenu(2, "\pFile"), 0);
  109.     AppendMenu(menu, "\pQuit/Q");
  110.     InsertMenu(menu = NewMenu(3, "\pEdit"), 0);
  111.     AppendMenu(menu, "\pUndo/Z;(-;Cut/X;Copy/C;Paste/V;Clear");
  112.     DrawMenuBar();
  113.     
  114.         /*  ready to receive events  */
  115.         
  116.     FlushEvents(everyEvent, 0);
  117.     InitCursor();
  118.     console_environment = 1;
  119. }
  120.  
  121.  
  122. Boolean AppleEventsInstalled ()
  123. {
  124.     OSErr err;
  125.     long  result;
  126.  
  127.     // THINK C's MacTraps library provides glue for Gestalt, so
  128.     // it can be called safely under System 6. If an error is
  129.     // returned, then Gestalt for the AppleEvents Selector is
  130.     // not available (this also means that Apple Events are
  131.     // not available)
  132.     err = Gestalt (gestaltAppleEventsAttr, &result);
  133.     return (!err && ((result >> gestaltAppleEventsPresent) & 0x0001));
  134.                         // return TRUE if there is n                                            // error and the proper bit of
  135.                         // result is set
  136. }
  137.  
  138. OSErr    MyGotRequiredParams (AppleEvent *theAppleEvent)
  139. {
  140.     DescType    returnedType;
  141.     Size    actualSize;
  142.     OSErr    myErr;
  143.  
  144.     myErr = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr,
  145.                     typeWildCard, &returnedType,
  146.                     nil, 0, &actualSize);
  147.  
  148.     if (myErr == errAEDescNotFound)    // you got all the required
  149.                                             //parameters
  150.         return    noErr;
  151.     else
  152.         if (myErr == noErr)  // you missed a required parameter
  153.             return    errAEParamMissed;
  154.         else    // the call to AEGetAttributePtr failed
  155.             return    myErr;
  156. }
  157.  
  158.  
  159. pascal OSErr  MyHandleODoc (AppleEvent *theAppleEvent, AppleEvent* reply, long handlerRefCon)
  160. {
  161.     
  162.     FSSpec        myFSS;
  163.     AEDescList    docList;
  164.     OSErr        err;
  165.     long        index,itemsInList;
  166.     Size        actualSize;
  167.     AEKeyword    keywd;
  168.     DescType    returnedType;
  169.     FILE         *f;
  170.         StringHandle    pathHandle;
  171.         short        itemHit=0,
  172.                 count=0;
  173.         
  174. //printf("ODOC invoked…\n");
  175.         
  176.     // get the direct parameter--a descriptor list--and put it into a docList
  177.     err = AEGetParamDesc (theAppleEvent, keyDirectObject, typeAEList,
  178.             &docList);
  179.     if (err)
  180.             return err;
  181.  
  182.     // check for missing parameters
  183.     err = MyGotRequiredParams (theAppleEvent);
  184.     if (err)
  185.             return err;
  186.  
  187.     // count the number of descriptor records in the list
  188.     err = AECountItems (&docList, &itemsInList);
  189.     
  190.     // allocate for pathname with Toolbox-calls
  191.     pathHandle = (StringHandle) NewHandle(sizeof(Str255));
  192.     HLock((Handle) pathHandle);
  193.             
  194.             
  195.     // now get each descriptor record from the list, coerce the returned
  196.     // data to an FSSpec record, and open the associated file
  197.     for (index = 1; index <= itemsInList; index++) {
  198.  
  199.             err = AEGetNthPtr (&docList, index, typeFSS, &keywd,
  200.                             &returnedType, (Ptr) &myFSS, sizeof(myFSS),&actualSize);
  201.             if (err)
  202.                     return err;
  203.             PtoCstr(myFSS.name);
  204.             // assemble full pathname to the current directory...
  205.             GetFullPath(myFSS.parID,myFSS.vRefNum,*pathHandle);
  206.             // ...and add the file's name
  207.             strcat((char *) *pathHandle,(const char *) myFSS.name);
  208.             testlength((char *)  *pathHandle);
  209.             // test if file can be opened
  210.             if(!(f = fopen((const char *) *pathHandle,"a"))){
  211. //                InitToolbox();
  212.                 do      // and warn with an alert if necessary
  213.                 {
  214. //                    itemHit = Alert(rCannotOpenFile, nil);
  215.                     itemHit = CautionAlert(rCannotOpenFile, nil);
  216. //                    Identisch bis auf, nur wird kein Icon Ausgegeben, s. THINK Ref., Amoroso, 8.9.93
  217.                 } while(itemHit != dOKButton);
  218.                             GenExit(1);
  219.                         }
  220.                         // put pathname into an argv-array    
  221.             strcpy((char *) argv[count], (const char *) *pathHandle);
  222.             argc = ++count;
  223.             fclose(f);
  224.     }
  225.     HUnlock((Handle) pathHandle);
  226.     DisposeHandle((Handle) pathHandle);
  227.     gDone = TRUE;
  228.     err = AEDisposeDesc (&docList);
  229. //printf("argc in odoc: %i",argc);
  230. //printf("PRG in odoc: %s\n",*(argv));
  231. //printf("CON in odoc: %s\n",*(argv+1));
  232. //printf("DAT in odoc: %s\n",*(argv+2));
  233. //printf("MyHandleOdoc korrekt verlassen!!");
  234. }
  235.  
  236.  
  237. void GetFullPath(long DirID, short vRefNum, StringPtr fullPath)
  238. {
  239.     CInfoPBRec    myPB;    
  240.     DirInfo        *dpb = (DirInfo *) &myPB;
  241.     Str255        dirName;
  242. // Ergänzung Amoroso ANFANG    
  243.     char         *HelpdirName;
  244.     int        error = 0;
  245. // Ergänzung Amoroso ENDE    
  246.     OSErr        myErr;
  247.     
  248.     // initialize dpb
  249.     dpb->ioNamePtr = dirName;
  250.     dpb->ioVRefNum = vRefNum;
  251.     dpb->ioDrParID = DirID;
  252.     dpb->ioFDirIndex = -1;
  253.     fullPath[0] = '\0';
  254.     
  255. // Ergänzung Amoroso ANFANG
  256.     error = (NULL == (HelpdirName = (char *) calloc (256,sizeof(char))));
  257.     if (!error)
  258.     do
  259.     {
  260.         HelpdirName = (char *)dirName;
  261.         CtoPstr(HelpdirName);        
  262. //    do
  263. //    {
  264. //        CtoPstr(dirName);
  265. //NICHT SAUBER, DA CtoPstr eigentlich (char *) erwartet, dirName aber unsigned char[] ist!
  266. //DAHER: ERGÄNZUNGEN...
  267. // Ergänzung Amoroso ENDE    
  268.         dpb->ioDrDirID = dpb->ioDrParID;
  269. // Ergänzung Amoroso ANFANG 2        
  270. //NICHT SAUBER, DA PBGetCatInfo eigentlich (CInfoPBRec *) erwartet, dpb aber (DirInfo *) ist!
  271. //DAHER: ERGÄNZUNGEN 2...
  272.         myErr = PBGetCatInfo(&myPB,FALSE);
  273. //        myErr = PBGetCatInfo(dpb,FALSE);
  274. // Ergänzung Amoroso ENDE 2    
  275.         PtoCstr(dirName);
  276.         strcat((char *) dirName,":");
  277.         strcat((char *) dirName, (const char *) fullPath);
  278.         
  279.         strcpy((char *) fullPath,(const char *) dirName);
  280.         testlength((char*) fullPath);    
  281.     }while(dpb->ioDrDirID != fsRtDirID);
  282. }            
  283.                  
  284.  
  285. void DoError(OSErr myErr)
  286. {
  287.     gDone = TRUE;
  288. }
  289.  
  290.  
  291. pascal OSErr  MyHandlePDoc (AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefCon)
  292. {
  293.     short    itemHit=0;
  294. //printf("PDOC invoked…\n");
  295. //GenOutAcknowledge(ModusReturn);
  296.     
  297.     // StopAlert if PDoc-Event was received 
  298. //    InitToolbox();
  299.     do
  300.     {
  301. //        itemHit = Alert(rNoPDocAlert, nil);
  302.         itemHit = StopAlert(rNoPDocAlert, nil);
  303. //        Identisch bis auf, nur wird kein Icon Ausgegeben, s. THINK Ref., Amoroso, 8.9.93
  304.     } while(itemHit != dOKButton);
  305.     GenExit(2);
  306. }
  307.  
  308. // QuitApplicationEvent received
  309.  
  310. pascal OSErr  MyHandleQuit (AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefCon)
  311. {        
  312. //printf("QAPP invoked…\n");
  313.     // set exit-condition true if QuitApp-Event received
  314.     gDone = TRUE;
  315.     return noErr;
  316. }
  317.  
  318. // OpenApplicationEvent received
  319.  
  320. /*pascal OSErr  MyHandleOApp (AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefCon)
  321. {    
  322. //printf("OAPP1 invoked…\n");
  323.     argc = 0;
  324.     return noErr;
  325. }*/
  326. // Ersetzt durch Version von MyHandleOApp die Alert ausgibt, Amoroso, 8.9.93
  327.  
  328. pascal OSErr  MyHandleOApp (AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefCon)
  329. {
  330.     short    itemHit=0;
  331.     
  332.     // StopAlert if PDoc-Event was received 
  333. //printf("OAPP2 invoked…\n");
  334.  
  335. //    InitToolbox();
  336.     do
  337.     {
  338. //        itemHit = Alert(rNoOAppAlert, nil);
  339.         itemHit = StopAlert(rNoOAppAlert, nil);
  340. //        Identisch bis auf, nur wird kein Icon Ausgegeben, s. THINK Ref., Amoroso, 8.9.93
  341.     } while(itemHit != dOKButton);
  342.     GenExit(0);
  343. }
  344.  
  345.  
  346. char **GetProgParams(int *pargc)
  347. {
  348.     Boolean        aEvents=FALSE,
  349.             eventThere=FALSE;
  350.     EventRecord    theEvent;
  351.     OSErr        myErr=0;
  352.     int         i=0,
  353.             error=0;
  354.     char        **ppargv;
  355.     char         *ModNam;
  356.     FILE        *fp;
  357.     
  358. #ifdef option_smartparams
  359.     char        *helpArgv[1];
  360.         int        dat_num = 0,
  361.                 con_num = 0;
  362.         FILE         *fs = NULL;
  363. #endif //ifdef option_smartparams
  364.     
  365.     InitTBandCON();
  366. //     //allocate pointer-array for *argvs
  367.     ppargv = (char **) NewPtr((maxFiles)*sizeof(char *));
  368. //    // first parameter is the program's name -> get it!    
  369.     *ppargv = (char *) NewPtr(MaxFullPathName + 5 + 6 + 1);        //32 char, 0 oder length, Trennzeichen, 4 char Creator, Trennzeichen, max. 5 char Modifiers
  370.     GetProgName(*ppargv);
  371.     // next parameters are the files' full pathnames they are set below...
  372.     for(i=1;i<maxFiles;i++)
  373.     {
  374. //        *(ppargv+i) = (char *) NewPtr(strlen((const char *) argv[i-1])+1); Nicht am falschen Ende sparen!
  375.         *(ppargv+i) = (char *) NewPtr(256);
  376.         strcpy(*(ppargv+i),"\0");
  377.     }
  378.  
  379.     if(!(ModNam = (char *)calloc((MaxFileName + 6),sizeof(char))))
  380.         GenExit(4);
  381.     strcpy(ModNam, *ppargv);
  382.     CtoPstr(ModNam);
  383.     *ModNam = *ModNam - 5;
  384. //    Creator und ":" NICHT ausgeben!
  385.     ParamText((unsigned char *) ModNam, 0, 0, 0);
  386.     aEvents = AppleEventsInstalled();
  387. //printf("aEvents: %i\n",aEvents);
  388.  
  389.     if (aEvents) {
  390. //printf("Entering Block after if (aEvents) {…\n");
  391. //printf("Trying to install odoc\n");
  392.                 // Install Apple-Event-Handlers
  393.         myErr = AEInstallEventHandler (kCoreEventClass, kAEOpenDocuments,&MyHandleODoc,0, FALSE);
  394.         if(myErr) {
  395. //printf("Installation of odoc failed\n");
  396.             DoError(myErr);
  397.         }
  398. //printf("Trying to install oapp\n");
  399.         myErr = AEInstallEventHandler (kCoreEventClass, kAEOpenApplication,MyHandleOApp,0, FALSE);
  400.         if(myErr) {
  401. //printf("Installation of oapp failed\n");
  402.             DoError(myErr);
  403.         }
  404. //printf("Trying to install pdoc\n");
  405.         myErr = AEInstallEventHandler (kCoreEventClass, kAEPrintDocuments,&MyHandlePDoc,0, FALSE);
  406.         if(myErr) {
  407. //printf("Installation of pdoc failed\n");
  408.             DoError(myErr);
  409.         }
  410. //printf("Trying to install qapp\n");
  411.         myErr = AEInstallEventHandler (kCoreEventClass, kAEQuitApplication,&MyHandleQuit,0, FALSE);
  412.         if(myErr) {
  413. //printf("Installation of qapp failed\n");
  414.             DoError(myErr);
  415.         }        
  416. //FlushEvents (everyEvent,kHighLevelEvent); Weg wg. Modifierbestimmung!
  417. //printf("Just survived FlusheEvents\n");
  418. //error = (!(fp = fopen("BS CO.log","w")));
  419. //InitConsole(); Besser am Anfang und Lokal!!! vgl.: InitTBandCON
  420. //if (error)
  421. //    GenExit(5);
  422.         do{
  423.             eventThere = EventAvail ( everyEvent, &theEvent );
  424.             Modis = theEvent.modifiers;
  425. //            TestStartMods(Modis);
  426.             GetStartMods(*ppargv, Modis);
  427.             eventThere = EventAvail ( highLevelEventMask, &theEvent );
  428. //printf("Just survived EventAvail, returned: %i\n",eventThere);
  429. //fprintf(fp,"theEvent.what= %i\n",theEvent.what);
  430. //Wenn alle Dateioperationen hier rausfallen und das folgende printf gemacht wird geht es auch mit Tasten!!!
  431. //printf("theEvent.what= %i\n",theEvent.what);
  432.         }while(!eventThere);
  433. //fprintf(fp,"Schleife verlassen, jetzt kommt GetNextEvent()…");
  434.         GetNextEvent ( highLevelEventMask, &theEvent );
  435. //printf("Just survived GetNextEvent, returned: %i\n",eventThere);
  436. //fprintf(fp,"Just survived GetNextEvent, returned: %i\n",eventThere);
  437.         if (theEvent.what == kHighLevelEvent){
  438. //printf("Trying to invoke AEProcessAppleEvent…\n");
  439. //fprintf(fp,"Trying to invoke AEProcessAppleEvent…\n");
  440.             myErr = AEProcessAppleEvent (&theEvent);
  441. //printf("Invoked AEProcessAppleEvent, returned: hi:%hi \n",myErr);
  442. //fprintf(fp,"Invoked AEProcessAppleEvent, returned: hi:%hi \n",myErr);
  443.             if(myErr){
  444. //printf("Invoking DoError…\n");
  445.                 DoError(myErr);    
  446.             }
  447.         }
  448. //        GetStartMods(*ppargv, theEvent.modifiers); Hier zu spät, da nur HighLevelEvent durchkommt, Mods = 0!
  449.     }    
  450.     // next parameters are the files' full pathnames
  451.     for(i=1;i<argc + 1;i++)
  452.     {
  453. //        *(ppargv+i) = (char *) NewPtr(strlen((const char *) argv[i-1])+1); Hier nicht mehr nötig!!
  454.         strcpy(*(ppargv+i),(const char *) argv[i-1]);
  455.     }
  456.     
  457.     // close with nil-Pointer and increase argc
  458. //    *(ppargv+argc+1) = nil;
  459. //    Feste Array-Länge, nicht nötig!!
  460.     *pargc = ++argc;
  461. //printf("argc in GetProgParams: %i",argc);
  462. //printf("PRG in GetProgParams: %s\n",*(argv));
  463. //printf("CON in GetProgParams: %s\n",*(argv+1));
  464. //printf("DAT in GetProgParams: %s\n",*(argv+2));
  465. //printf("GetProgParams korrekt verlassen!!");
  466. //fclose(fp);
  467. #ifdef option_smartparams
  468.     for(i=1;i<argc;i++){
  469.         if (**(ppargv+i) != 0)
  470.             error = (NULL == (fs = fopen(*(ppargv+i),"r")));
  471.         if (fs != NULL){
  472.             if (!error){
  473. //printf("\nGetProgParams!");
  474. //printf("\n Suche in argv[%i]:\n %.255s\n",i,*(ppargv+i));
  475. //printf("\nError vor 1. Aufr. checkType (Index %i): %i",i,error);            
  476. //GenOutAcknowledge(ModusReturn);
  477.                 error = checkType(fs, "&Type=Control", &con_num, i);
  478.             }
  479.             else 
  480.                 GenExit(99);
  481. //printf("\ncon_num: %i",con_num);            
  482.             if (!error)
  483.                 error = fseek(fs, 0L, SEEK_SET);
  484.             if (!error){
  485. //printf("\nGetProgParams!");
  486. //printf("\n Suche in argv[%i]:\n %.255s\n",i,*(ppargv+i));
  487. //printf("\nError vor 2. Aufr. checkType (Index %i): %i",i,error);            
  488. //GenOutAcknowledge(ModusReturn);
  489.                 error = checkType(fs, "&Type=Data", &dat_num, i);
  490.             }
  491.             if (fs)
  492.                 fclose(fs);
  493.             fs = NULL;
  494.         }
  495.     }
  496. //printf("\n\nCon/Dat: %i, %i\n\n",con_num,dat_num);
  497. //for(i=1;i<argc;i++)
  498. //printf("\nargv[%i]: %s",i,*(ppargv+i));
  499.     if ((con_num > 2) && (dat_num > 2)){
  500.         error = swapArgv(*(ppargv+1), *(ppargv+con_num));
  501.         if(error)
  502.             GenExit(100);
  503.         error = swapArgv(*(ppargv+2), *(ppargv+dat_num));
  504.         if(error)
  505.             GenExit(100);
  506.     }    
  507.     else if ((bsintmin(con_num,dat_num) < 3) && (bsintmax(con_num,dat_num) > 2)){    
  508.         if (bsintmin(con_num,dat_num) == con_num){
  509.             error = swapArgv(*(ppargv+1), *(ppargv+con_num));
  510.             if(error)
  511.                 GenExit(100);
  512.             error = swapArgv(*(ppargv+2), *(ppargv+dat_num));
  513.             if(error)
  514.                 GenExit(100);
  515.         }
  516.         else if (bsintmin(con_num,dat_num) == dat_num){
  517.             error = swapArgv(*(ppargv+2), *(ppargv+dat_num));
  518.             if(error)
  519.                 GenExit(100);
  520.             error = swapArgv(*(ppargv+1), *(ppargv+con_num));
  521.             if(error)
  522.                 GenExit(100);
  523.         }
  524.     }    
  525.     else if    (((con_num * dat_num) < 3) && con_num > dat_num){    
  526.             error = swapArgv(*(ppargv+1), *(ppargv+2));
  527.     }
  528. //for(i=1;i<argc;i++)
  529. //printf("\nargv[%i]: %s",i,*(ppargv+i));
  530. //GenOutAcknowledge(ModusReturn);
  531.  
  532. #endif //ifdef option_smartparams
  533.         
  534.     return ppargv;
  535.  
  536. }
  537.  
  538. int GetProgName(char *Argv1){
  539.  
  540.     ProcessInfoRec         myInfoRec;
  541.     ProcessSerialNumber     myPSN;
  542.     FSSpec             myFSSpec;
  543.     OSErr             OSError = 0;
  544.     int             i = 0,
  545.                 error = 0,
  546.                 StrLength = 0;
  547.     char             helpStr[MaxFileName + 6], helpStrPtr,
  548.                 *TypePtr, *StrPtr;    
  549.     myInfoRec.processInfoLength = (unsigned long)sizeof(ProcessInfoRec);
  550.     myInfoRec.processName = (unsigned char *) calloc (sizeof (unsigned char),MaxFullPathName +5);
  551.     myInfoRec.processAppSpec = &myFSSpec;
  552.     OSError = GetCurrentProcess(&myPSN);
  553.     if(!OSError)
  554.         OSError = GetProcessInformation(&myPSN, &myInfoRec);
  555.     if(!OSError){
  556.         strcpy(Argv1,PtoCstr(myInfoRec.processName));
  557.         strcat(Argv1,":\0");
  558. // N.B.: ":" Darf auf dem Mac nicht für Dateinamen verwendet werden!!!
  559.         StrLength = (int) strlen(Argv1);
  560.         StrPtr = (Argv1 + StrLength);
  561.         TypePtr = (char *) &myInfoRec.processSignature;
  562.         for (i=0;i<4;i++)
  563.             *(StrPtr++) = *(TypePtr++);
  564.         *StrPtr = 0;    
  565.     }
  566.     return (error | (int)OSError);
  567. }
  568.  
  569. int GetStartMods(char *Argv1, unsigned short mods)    
  570. {
  571.     FILE *Nptr = NULL;
  572. static  int count = 1;    
  573.     int i = 0;
  574.     unsigned short testshort = 1;
  575.     char Num[5] ="";
  576.     char Name[33] = "";
  577.     
  578.     sprintf(Num, "%i", count);
  579.     strcat(Name,"GModifiers");
  580.     strcat(Name,(const char *)Num);
  581.     strcat(Name,".txt");
  582. //    Nptr = fopen("ModifiersApple.txt","w");
  583. //    fprintf(Nptr, "Short Modifiers: %i\nBinär: ", (int) mods );
  584. //    for (i=1; i <= 16; i++){
  585. //        fprintf(Nptr, "mods & testshort: %i\n mods: %i\n testshort: %i\n", (int)(mods & testshort), mods, testshort);
  586. //        fprintf(Nptr, "%i", (int)((mods & testshort) != (unsigned short) 0));
  587. //        testshort = testshort << 1;
  588. //    }
  589.     strcat(Argv1,":\0");
  590. // N.B.: ":" Darf auf dem Mac nicht für Dateinamen verwendet werden!!!
  591.     if(mods & (unsigned short)cmdKey)
  592.         strcat(Argv1,"c\0");
  593.     if(mods & (unsigned short)shiftKey)
  594.         strcat(Argv1,"s\0");
  595.     if(mods & (unsigned short)alphaLock)
  596.         strcat(Argv1,"a\0");
  597.     if(mods & (unsigned short)optionKey)
  598.         strcat(Argv1,"o\0");
  599.     if(mods & (unsigned short)controlKey)
  600.         strcat(Argv1,"k\0");        
  601. // String with ":modifiers csaok" if pressed while startup
  602. // Control,Shift,Alpha Lock,Option,KControl...
  603. //    fprintf(Nptr, "\nARGV in GetStartMods: %s", Argv1);
  604. //    fclose(Nptr);
  605.     return(0);
  606. }
  607.  
  608. int TestStartMods(unsigned short mods)    
  609. {
  610.     FILE *Nptr = NULL;
  611. static  int count = 1;    
  612.     int i = 0;
  613.     unsigned short testshort = 1;
  614.     char Num[5] ="";
  615.     char Name[33] = "";
  616.     
  617.     sprintf(Num, "%i", count);
  618.     strcat(Name,"GModifiers");
  619.     strcat(Name,(const char *)Num);
  620.     strcat(Name,".txt");
  621.     Nptr = fopen((const char *)Name,"w");
  622.     fprintf(Nptr, "Short Modifiers: %i\nIn Bits: ", (int) mods );
  623.     for (i=1; i <= 16; i++){
  624.         fprintf(Nptr, "%i", (int)(mods & testshort));
  625.         testshort << 1;
  626.     }
  627.     fclose(Nptr);
  628.     return(0);
  629. }                                
  630.                                 
  631.  
  632.  
  633. Boolean GetQuitReq(int tick)
  634. {
  635.     EventRecord     theEvent;
  636.     OSErr        myErr;
  637.     
  638.     // check Event-Queue
  639.     if( WaitNextEvent ( everyEvent, &theEvent, tick, nil ) ) {
  640.                 switch (theEvent.what) {
  641.                 
  642.                 case kHighLevelEvent:
  643.                         
  644.                         myErr = AEProcessAppleEvent (&theEvent);
  645.                         if(myErr)
  646.                             DoError(myErr);                                        
  647.                         if(gDone)
  648.                             return TRUE;            
  649.                         else     return FALSE;
  650.                             
  651.                 default:
  652.                         return FALSE;
  653.                         }
  654.                 }
  655. }
  656.  
  657. void testlength(char *path)
  658. {
  659.     short itemHit = 0;
  660.     
  661.     if (strlen(path) > 255){
  662. //        InitToolbox();
  663.         do
  664.         {
  665. //            itemHit = Alert(rPathTooLong,nil);
  666.             itemHit = StopAlert(rPathTooLong,nil);
  667. //            Identisch bis auf, nur wird kein Icon Ausgegeben, s. THINK Ref., Amoroso, 8.9.93
  668.         }while(itemHit != dOKButton);
  669.         GenExit(0);
  670.     }
  671. }
  672.  
  673.  
  674. int GetFileInfo(char * FName, unsigned long *Type, unsigned long *Creator){
  675.     
  676.     FInfo    myFInfo;
  677.     Str255    myFName, *myFNamePtr;
  678.     int    error = 0;
  679.     OSErr    OSError = 0;
  680.     
  681.     myFNamePtr = &myFName;
  682.     error = (255 < (int)strlen(FName));
  683.     if(!error)
  684.         strcpy((char *)myFNamePtr,FName);
  685.     if(!error){
  686.         CtoPstr((char *)myFName);
  687.         OSError = HGetFInfo(0, 0, myFName, &myFInfo);
  688.         if(!OSError){
  689.             *Type = (unsigned long) myFInfo.fdType;
  690.             *Creator = (unsigned long) myFInfo.fdCreator;
  691.         }
  692.     }
  693.     return (error | (int) OSError);
  694. }
  695.  
  696. int SetFileInfo(char * FName, unsigned long Type, unsigned long Creator){
  697.     
  698.     FInfo    myFInfo;
  699.     Str255    myFName, *myFNamePtr;
  700. //    myNewName, *myNewNamePtr;
  701.     int    error = 0;
  702.     OSErr    OSError = 0;
  703.     
  704.     myFNamePtr = &myFName;
  705.     error = (255 < (int)strlen(FName));
  706.     if(!error)
  707.         strcpy((char *)myFNamePtr,FName);
  708.     if(!error){
  709.         CtoPstr((char *)myFName);
  710.         OSError = HGetFInfo(0, 0, myFName, &myFInfo);
  711.         if(!OSError){
  712.             myFInfo.fdType = (OSType)Type;
  713.             myFInfo.fdCreator = (OSType)Creator;
  714.             OSError = HSetFInfo(0, 0, myFName, &myFInfo);
  715.         }
  716.     }
  717.     return (error | (int) OSError);
  718. }
  719.  
  720. #ifdef option_smartparams
  721. int checkType(FILE *fp, char *keyWord, int *result, int count)
  722. {
  723.     char    *word = NULL,
  724.         *word_ptr = NULL,
  725.         *char_ptr = NULL,
  726.         *UpperKeyWord = NULL,
  727.           c = 0;
  728.       int     compareLength = 0,
  729.           found = 0,
  730.           i = 0,
  731.           error = 0;
  732.       long     fp_pos = 0,
  733.         fphelp = 0;
  734.  
  735.     
  736. //printf("\ncheckType!");
  737. //printf("\nError: %i, Result: %i, Count: %i",error,*result,count);
  738.     
  739.     compareLength = (int)strlen(keyWord);
  740. //printf("\nComparelength: %i", compareLength);
  741.     if(!*result)
  742.         error = (NULL == (UpperKeyWord = (char *) calloc((size_t)(1 + compareLength),sizeof(char))));
  743. //printf("\n!Error && !Result: %i",(!error && !*result));
  744.     if(!*result && !error)
  745.         error = (NULL == (word = (char *) calloc((size_t)(1 + compareLength),sizeof(char))));
  746.     else
  747.         return(error);
  748. //printf("\nPointer initialisiert: %p, %p", UpperKeyWord, word);
  749.     if (!*result && !error){
  750.         strcpy(UpperKeyWord,(const char *)keyWord);
  751.         word_ptr = UpperKeyWord;
  752.         char_ptr = keyWord;
  753.         if (*char_ptr != 0) 
  754.             do{
  755.                 c = *char_ptr;
  756. //printf("\nchar_ptr: %c",c);
  757.                 char_ptr++;    
  758.                 if(isgraph(c))               
  759.                     *word_ptr = toupper(c);
  760. //printf("\nword_ptr: %c",toupper(c));
  761.                 word_ptr++;
  762. //GenOutAcknowledge(ModusReturn);                            
  763.             }while (c);
  764. //printf("\nSuche nach Keyword: %s bzw.: %s",keyWord,UpperKeyWord);                    
  765.         word_ptr = word;
  766.         while(!found){
  767.             do{
  768.                 c = fgetc(fp);
  769.             }while((c != '&') && (c != EOF));            //sucht & in der Datei
  770. //printf("\nChar %i gefunden, gesucht %i",c,'&');
  771. //printf("\nDateizeiger = %i",ftell(fp));
  772. //GenOutAcknowledge(ModusReturn);                        
  773.             if(c == EOF){
  774.                 free(word);
  775.                 free(UpperKeyWord);
  776.                 return(error);
  777.             }
  778.             fphelp = ftell(fp);                //3 Zeilen eingefügt um Dateizeiger wieder vor gefundenes & zu bringen
  779.             fphelp--;
  780.             fseek(fp,fphelp,SEEK_SET);
  781.             fp_pos = ftell(fp);                //fpos wird zugewiesen bevor der Vergleich beginnt!
  782.                i = 0;
  783.             while((i < compareLength) && (c != ';')){      //kopiert compareLength Zeichen in strin word
  784.                 c = fgetc(fp);
  785.                 if(c == EOF){
  786.                     free(word);
  787.                     free(UpperKeyWord);
  788.                     return(error);
  789.                 }
  790.                 if(isgraph(c)){               //isgraph(' ') = 0!!!!!
  791.                     *word_ptr = toupper(c);
  792.                     word_ptr++;
  793.                     i++;
  794.                 }
  795.             }
  796.             *word_ptr = '\0';                    // string in word wird abgeschlossen
  797. //printf("\nEingelesenes Wort: %s",word);                    
  798. //printf("\nDateizeiger = %i",ftell(fp));
  799. //GenOutAcknowledge(ModusReturn);                        
  800.         if(!strncmp(word,UpperKeyWord,compareLength)){        // Identität => strncmp = 0!
  801.             
  802.             found = 1;                    // gefunden
  803.             *result = count;                // Index vermerken
  804. //printf("\nÄndere Result: %i ",*result);            
  805.         }
  806.         else
  807.             word_ptr = word;                // Übertragungszeiger wieder auf Anfang für word reservierten Bereich
  808.         } // while !found                     // solange bis gefunden!
  809.     free(word);
  810.     free(UpperKeyWord);
  811.     }
  812.     else 
  813.         if(UpperKeyWord != NULL)
  814.             free(UpperKeyWord);
  815. //printf("\nRückgabewert: %i",error);
  816.     return(error);
  817. }
  818.  
  819. int swapArgv(char *argFrom, char *argTo)                // Swap two argvs
  820. {
  821.     char HelpStr[MaxFullPathName];
  822.     
  823.     strcpy(HelpStr, (const char *)argTo);
  824.     strcpy(argTo, (const char *)argFrom);
  825.     strcpy(argFrom, (const char *)HelpStr);
  826.     return 0;
  827. #endif //ifdef option_smartparams
  828. #endif //ifdef modus_mcp
  829.  
  830. #endif //ifdef apple
  831.  
  832. #endif //ifndef bsoc